<%@ include file="/WEB-INF/views/commonJSTL.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>${s_UserPharmacy.pharmacy.name}</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%@ include file="/WEB-INF/views/commonResources.jsp" %>

<script type="text/javascript">
	$(document).ready(function(){
		$(".addNewDosage").click(function(){
			$("#dialogFormDosage").load("invoiceDosageFormDosageNew",function(){
				openDialogModalForm("#dialogFormDosage","Agregar Dosificacion",null);
			});
		});		
		$("#dialogFormDosage").dialog({autoOpen: false, height: 300, width: 500,modal: true,
			open: function(event, ui){		
				//$("#divShowFormBill").print();
			},
			buttons: {
	            "Aceptar": function() {
	            	var flag = $("#formDosage").valid();
	                if(flag){
		            	var urlTemp = ($("#dosageIdTemp").val() != '')?'invoiceDosageFormDosageEdit':'invoiceDosageFormDosageNew';
		            	$.ajax({ 
		            		type: "POST",
		            		url: urlTemp,
                            data: $('#formDosage').serialize(),
			           	    success:function(data){
			           	    	if($("#dosageIdTemp").val() == ''){
				           	    	if(data == 2)
				           	    		alert("Existe uno en espera!!!!");
			           	    	}else{
			           	    		if(data == 1)
				           	    		alert("Se modifico con Exito!!!!!");
			           	    	}
			           	    	$("#dialogFormDosage").dialog( "close" );
			           	    	location.href = "invoiceDosage?_menuId="+"<c:out value="${param._menuId}"/>&_subMenuId="+"<c:out value="${param._subMenuId}"/>&_optionId="+"<c:out value="${param._optionId}"/>"; 
			           		}, 
			           		error: 	function(){alert('Error en request..');} }); 
	            	}
	            },
	            Cancel: function() { $( this ).dialog( "close" );}
			},
			close: function(){ $( this ).dialog( "close" ); }
		});	
		
	});
	function functionDialogFormDosageEdit(dosageId){
		$("#dialogFormDosage").load("invoiceDosageFormDosageEdit?_dosageId="+dosageId,function(){
			openDialogModalForm("#dialogFormDosage","Modificar Dosificacion",null);
		});
	}
	function removeDosage(dosageId,keyDosage){
		if(confirm("¿Estas seguro de Eliminar a : "+keyDosage+"?")){
            $.ajax({
                url: "ajaxRemoveInvoiceDosage",
                type: "GET",
                data:{dosageId:dosageId},
                beforeSend:function(obj){
                    $('#invoiceDosage').css({display:'none'});
                    $('#imgLoad').css({display:'block'});
                },
                success:function(res){
                	alert(res+' a '+keyDosage);
           	    	location.href = "invoiceDosage?_menuId="+"<c:out value="${param._menuId}"/>&_subMenuId="+"<c:out value="${param._subMenuId}"/>&_optionId="+"<c:out value="${param._optionId}"/>"; 
                },
                complete:function(){
                    $('#imgLoad').css({display:'none'});
                    $("#invoiceDosage").css({display:'block'});
                },
                error: function(res){ alert("Error! al Eliminar"); }
            });
        }
	}
</script>
</head>

<body>
<div id="top-wrap">
	<%@include file="../../../head.jsp"  %>
	<div id="bodySpace">
		
	    <div class="clearfix" id="middle" style="position: absolute">  <!-- aqui va la ruta -->
	        <!-- aqui va el arbol de entrada -->
	        <div id="breadcrumb">
	            <ul>
                    <li><a href="<spring:url value="/mainFront?" htmlEscape="true" />">Home</a></li>	
                    <li><span style="color:#666"><fmt:message key="title.operation"/></span></li>		
                    <li><span style="color:#666"><fmt:message key="title.nationalTaxation"/></span></li>		
                    <li class="current-page"><span class="end"><span class="middle"><fmt:message key="title.invoiceDosage"/></span></span></li>
                </ul>
	        </div>
	    </div>
	    
	    <div id="principal">
            <!-- izquierda -->
            <div class="cuerpo2y" style="border: 0px solid"><br/><br/><!-- estos break son necesarios ya q uso absolute en css  cuerpo izquierdo-->
                <div class="izq">
					<%@include file="../../../bodyIzq.jsp" %>	
                </div>
                
                <div class="medio" style="border: 0px solid">
					<h2 class="decorado"><fmt:message key="title.dosage"/></h2></br></br> 
					
					<div id="dialogFormDosage"></div>	
					
					<div id="imgLoad" style="float: left;width: 100%;display: none;"><img src="<c:url value="/resources/images/imgLoad/ajax-loader.gif" />" width="32" height="32" alt="ajax-loader.gif" style="position:absolute; top:30%; left:50%;"/></div> 
					<div id="invoiceDosage">
						<table class="miReporte" style="width: 100%">
							<tr>
								<td style="text-align: right"><input type="button" class="boton addNewDosage" value="<fmt:message key="button.New"/>" title='<fmt:message key="onclick.add"/> <fmt:message key="title.New"/>.'/></td>
							</tr>
						</table>
						<table class="tabla_decorado" style="width: 100%">
							<thead>
								<tr>
									<th width="13%" class="th_decoradoRowspan"><fmt:message key="table.state"/></th>
									<th width="12%" class="th_decoradoRowspan"><fmt:message key="table.numAuthorization"/></th>
									<th width="15%" class="th_decoradoRowspan"><fmt:message key="table.deadlineOfEmission"/></th>
									<th width="35%" class="th_decoradoRowspan"><fmt:message key="table.keyDosage"/></th>
									<th width="10%" class="th_decoradoRowspan"><fmt:message key="table.lastBillIssued"/></th>
									<th width="15%" class="th_decoradoRowspan"><fmt:message key="table.actions"/></th>
								</tr>
							</thead>
							<tbody>
								<c:forEach var="item" items="${listDosage}"> 
									<tr class="tr_decorado">
										<td class="th_decorado" style="text-align: center">${(item.state == 2)?'Pendiente':(item.state == 1)?'Activo':(item.state == 0)?'Inactivo':'ningun valor '}</td>
										<td class="th_decorado" style="text-align: center">${item.orderNumber}</td>
										<td class="th_decorado" style="text-align: center"><fmt:formatDate pattern="dd/MM/yyyy" value="${item.deadline}"/></td>
										<td class="th_decorado" style="text-align: center">${item.key}</td>
										<td class="th_decorado" style="text-align: center">${item.lastNumBillIssued}</td>
										<td class="td_decoradoDerecha" style="text-align: center">
											<input type="button" value="<fmt:message key="button.edit"/>" onclick="functionDialogFormDosageEdit('${item.dosageId}')" class="botonRep" title="<fmt:message key="onclick.edit"/> ${item.key}"/>
											<input type="button" value="<fmt:message key="button.remove"/>" onclick="removeDosage('${item.dosageId}','${item.key}')" class="botonRep" title="<fmt:message key="onclick.remove"/> ${item.key}"/>
										</td>
									</tr>
								</c:forEach>
								<c:if test="${(empty listDosage)}">
									<tr class="tr_decorado">
										<td class="td_decorado" colspan="8" style="text-align:center"><span style="color:red"><fmt:message key="show.noExistSearchDosage"/></span></td>
									</tr>
							   </c:if> 
							</tbody>
						</table>
						<table class="miReporte" style="width: 100%">
							<tr>
								<td style="text-align: right"><input type="button" value="<fmt:message key="button.inactives"/>" onclick="showHide()" class="boton" title="<fmt:message key="onclick.inactives"/>"/></td>
							</tr>
						</table><br/><br/>	
					</div>	                               
                </div>
            </div><!--end of leftPan-->
            
            <div class="yDer" style="border: 1px solid #ccc;">
                  <%@include file="../../../notices.jsp" %>                       
            </div><!--end of rightPan-->
        </div><!--end main content -->
	</div>
</div>
</body>
</html>
